
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    "index_url": "behavior/record/index",
                    "add_url": "",
                    "edit_url": "",
                    "del_url": "behavior/record/del",
                    "multi_url": "",
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'garden_name', title: __('园区'), operate: false},
                        {field: 'building_name', title: __('楼栋'), operate: false},
                        {field: 'dorm_number', title: __('寝室'), operate: false},
                        {field: 'student_number', title: __('学号'), operate: false},
                        {field: 'b.number', title: __('学号'), visible: false},
                        {field: 'student_name', title: __('姓名'), operate: false},
                        {field: 'b.name', title: __('姓名'), visible: false},
                        {field: 'student_gender_text', title: __('性别'), operate: false},
                        {
                            field: 'created_at',
                            title: __('点评时间'),
                            sortable: true,
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange'
                        },
                        {field: 'score', title: __('点评分数'), operate: false},
                        {field: 'behavior_name', title: __('点评行为'), operate: false},
                        {field: 'record_user_group', title: __('点评人'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                commonSearch: true,
                searchFormVisible: true,

            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        api: {
            formatter: {
                url: function (value, row, index) {
                    return '<img style="max-width: 50px; max-height: 50px;" src="'+value+'">';
                },
            },
            bindevent: function () {

            }
        }
    };
    return Controller;
});
